$(function () {
    var url = "/except/shopcontroller/homepagebanner.do";
    var token = $("#token").val();
    if (isempty(token))
        token = "null";
    var jsonstr = "{token:" + token + "}";
    $.ajax({
        url: url,
        type: 'post',
        dataType: "json",
        data: {
            json: jsonstr
        },
        async: false,
        success: function (data) {
            var code = data.code;
            var message = data.message;
            var appendstr = '';
            if (code == 20013)
                appendstr = '<li><a href="#"><img src="img/onerror.jpg" /></a></li>';
            else if (code == 20000) {
                var datas = data.data;
                $(datas).each(function () {
                    // debugger
                    appendstr += '<div class="swiper-slide"><img src="' + this.img_address + '" onerror="imgerror(this,\'img/onerror.png\');"/></div>';
                });
                $("#banner").empty().append(appendstr).after('<div class="swiper-pagination"></div>');
                var mySwiper = new Swiper('.swiper-container', {
                    loop: true,
                    autoplay: 2000,
                    autoplayDisableOnInteraction: false,
                    pagination: '.swiper-pagination',
                    observer: true,//修改swiper自己或子元素时，自动初始化swiper
                    observeParents: true,//修改swiper的父元素时，自动初始化swiper
                });


                // 这段代码加上没得
                storymoreinfo(0);
                remove_advertising();  //删除广告
            } else {
                $("#hint_message").html(message);
                $("#hintbg").show();
            }
        },
        error: function (data) {
            alert("网络错误");
        }
    });
});

function storymoreinfo(page) {
    url = "/except/shopcontroller/homepagestory.do";
    var token = $("#token").val();
    if (isempty(token))
        token = "null";
    var jsonstr = "{token:" + token + "}";
    $.ajax({
        url: url,
        type: 'post',
        dataType: "json",
        data: {
            page: page,
            count: 10,
            json: jsonstr
        },
        async: false,

        success: function (data) {
            var code = data.code;
            var message = data.message;
            var storyinfo = "";
            if (code == 20000) {
                var datas = data.data;
                $(datas).each(function () {
                    // alert(""+this.story_logo);
                    var address = this.story_logo;
                    storyinfo += '<div class="item_div" onclick="storyinfo(\'' + this.story_id + '\', ' + this.type + ', \'' + this.shopid + '\');">' +
                        '<div style="border-radius: 6px;margin-bottom: 100px; height: 200px;overflow-y: hidden; background: url(' + address + ') no-repeat center;background-size: cover;width: 92%;margin: 0 auto;" onerror="imgerror(this,\'img/onerror.png\');"></div> ' +
                        // '<img class="item_img"  src="' + this.story_logo + '" onerror="imgerror(this,\'img/onerror.png\');"/>' +
                        '<span class="item_span_storename">' + this.story_name + '</span>' +
                        '<span class="item_span_desc">' + this.brief + '</span>' +
                        '</div>';
                });
                if (page == 0)
                    $("#storyinfo").empty().append(storyinfo);
                else
                    $("#storyinfo").append(storyinfo);
                $("#page").val(page * 1 + 1);
            } else if (code == 20013) {
                if (page == 0) {
                    $("#not_data").show();
                } else {
                    $("#nomore").show();
                }
            } else {
                $("#hint_message").html(message)
                $("#hintbg").show();
            }
        }
    });
}
$(window).scroll(function () {
    //$(document).scrollTop() 获取垂直滚动的距离
    //$(document).scrollLeft() 这是获取水平滚动条的距离
    if ($(document).scrollTop() <= 0) {
        storymoreinfo(0);
    }
    var page = $("#page").val();
    if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
        storymoreinfo(page);
    }
});

function storyinfo(storyid, type, shopid) {
    if (type == "1")
        location.href = "/except/files/shop_story.jsp?storyid=" + storyid + "&shopid=" + shopid;
    else
        location.href = "/except/files/story.jsp?storyid=" + storyid;
}